﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace DBLGen
{
	public class MethodCollection : IList<Method>
	{
		private Table _table;
		private List<Method> _items = new List<Method>();

		protected List<Method> Items
		{
			get
			{
				return _items;
			}
		}
		public MethodCollection() { }

		public MethodCollection(Table owner)
		{
			if (owner == null)
				throw new ArgumentNullException("owner");

			_table = owner;
		}

		public Method Find(string columnName)
		{
			foreach (Method c in Items)
				if (String.Compare(columnName, c.Name, true) == 0)
					return c;

			return null;
		}

		#region IList<Method> Members

		public int IndexOf(Method item)
		{
			return Items.IndexOf(item);
		}

		public void Insert(int index, Method item)
		{
			Items.Insert(index, item);
		}

		public void RemoveAt(int index)
		{
			Items[index].Table = null;
			RemoveAt(index);
		}

		public Method this[int index]
		{
			get
			{
				return Items[index];
			}
			set
			{
				Items[index] = value;
			}
		}

		#endregion

		#region ICollection<Column> Members

		public void Add(Method item)
		{
			Items.Add(item);
			item.Table = _table;
		}

		public void AddRange(IEnumerable<Method> items)
		{
			foreach (Method item in items)
				Add(item);
		}

		public void Clear()
		{
			Items.Clear();
		}

		public bool Contains(Method item)
		{
			return Items.Contains(item);
		}

		public void CopyTo(Method[] array, int arrayIndex)
		{
			Items.CopyTo(array, arrayIndex);
		}

		public int Count
		{
			get
			{
				return Items.Count;
			}
		}

		public bool IsReadOnly
		{
			get
			{
				return false;
			}
		}

		public bool Remove(Method item)
		{
			if (Items.Remove(item))
			{
				item.Table = null;
				return true;
			}

			return false;
		}

		#endregion

		#region IEnumerable<Method> Members

		public IEnumerator<Method> GetEnumerator()
		{
			return Items.GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.GetEnumerator();
		}

		#endregion

	}
}
